package cn.xlbweb.cli.controller;

import cn.xlbweb.cli.common.ServerResponse;
import cn.xlbweb.cli.common.TableResponse;
import cn.xlbweb.cli.pojo.dto.InsertUserDTO;
import cn.xlbweb.cli.pojo.dto.UpdateUserDTO;
import cn.xlbweb.cli.pojo.dto.ListUserDTO;
import cn.xlbweb.cli.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author: bobi
 * @date: 2019-02-04 00:55
 * @description:
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private IUserService iUserService;

    @GetMapping("xxx")
    public Object xxx() {
        return iUserService.xxx();
    }

    @ApiOperation(value = "查询当前登录用户", notes = "查询当前登录用户")
    @GetMapping("getCurrentUser")
    public ServerResponse getCurrentUser() {
        return iUserService.getCurrentUser();
    }

    @ApiOperation(value = "分页模糊查询用户", notes = "分页模糊查询用户")
    @RequiresPermissions("user:listUser")
    @GetMapping("listUser")
    public TableResponse listUser(@Valid ListUserDTO usersListDTO) {
        return iUserService.listUser(usersListDTO);
    }

    @ApiOperation(value = "添加用户")
    @RequiresPermissions("user:insertUser")
    @PostMapping("insertUser")
    public ServerResponse insertUser(InsertUserDTO insertUserDTO) {
        return iUserService.insertUser(insertUserDTO);
    }

    @GetMapping("getUser")
    public ServerResponse getUser(Integer userId) {
        return iUserService.getUser(userId);
    }

    @ApiOperation(value = "更新用户")
    @RequiresPermissions("user:updateUser")
    @PutMapping("updateUser")
    public ServerResponse updateUser(UpdateUserDTO updateUserDTO) {
        return iUserService.updateUser(updateUserDTO);
    }

    @ApiOperation(value = "删除用户")
    @RequiresPermissions("user:deleteUser")
    @DeleteMapping("deleteUser")
    public ServerResponse deleteUser(String ids) {
        return iUserService.deleteUser(ids);
    }
}
